import UIKit

/**
    B站：https://www.bilibili.com/video/BV144411C7Gg?p=48

    第48课
        1. 泛型类型限定
        2. 协议中类型限定
 */

class Data {
    var name: String
    init(name: String) {
        self.name = name
    }
}

// 任何值
func play<T:Any>(param: T) {
    print(param)
}

play(param: Data(name: "hellow"))


// 泛型 - 限定
func play2<T:Data>(param: T) {
    print(param.name)
}

play2(param: Data(name: "hellow"))

print("\n\n\n")
// ------------------------------------------------

protocol Test {
    associatedtype D
    func play(param: D)
}

class Student: Test {
    func play(param: String) {
        print(param)
    }
}

class Dog: Test {
    func play(param: Int) {
        print(param)
    }
}

class Cat: Test {
    func play(param: Data) {
        print(param.name)
    }
}

let s = Student()
s.play(param: "world")

let d = Dog()
d.play(param: 10)

let c = Cat()
c.play(param: Data(name: "cat"))
